<?php 
    require_once dirname(dirname(__FILE__)) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'html_generator.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_LIBRARIES . 'lib_pager.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_matches.php';
            $current_page = filter_input(INPUT_POST, "page");
            if (empty($current_page)) {
                $current_page = 1;
            }
            $page_size = filter_input(INPUT_POST, "page_size");
            $section_id = filter_input(INPUT_POST, "section_id");
            
            $list = api_matches::get_all_matches_hottest();
            $list_total = $list;
            $lib_pager = new lib_pager($list_total, $page_size);
            $total_page = $lib_pager->get_total_page();
            $current_page_list = $lib_pager->get_current_page_list($current_page);
?>
            <div class="row">
            <?php 
            foreach ($current_page_list as $item) {
                show_match_block($item, "");
            }
            ?>
            </div>
            <div class="ts-clear"></div>
            <div class = "text-center">
                <ul class = "pagination pagination-lg">
                    <li><span onclick="apply_<?php echo $section_id; ?>_page(<?php echo $current_page - 1; ?>);">&laquo;</span></li>
                    <?php 
                    if (!empty($total_page) && count($total_page) > 0) {
                        for ($page = 1; $page <= $total_page; $page++) { ?>
                            <li 
                                <?php if ($current_page != $page) {
                                    echo 'class="active"';
                                } ?>
                                >
                                <span onclick="apply_<?php echo $section_id; ?>_page(<?php echo $page; ?>);">
                                    <?php echo $page; ?>
                                </span>
                            </li>
                    <?php 
                        }
                    }?>
                    <li><span onclick="apply_<?php echo $section_id; ?>_page(<?php echo $current_page + 1; ?>);">&raquo;</span></li>
                </ul>
            </div>